﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

namespace CardInChina.Web.Mvc
{
    // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
    // visit http://go.microsoft.com/?LinkId=9394801

    public class MvcApplication : System.Web.HttpApplication
    {
        public static void RegisterGlobalFilters(GlobalFilterCollection filters)
        {
            filters.Add(new HandleErrorAttribute());
        }

        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                null, // Route name
                "search/{searchKey}", // URL with parameters
                new { controller = "Search", action = "Index", searchKey = UrlParameter.Optional } // Parameter defaults
            );

            routes.MapRoute(
                null, // Route name
                "category/{key}", // URL with parameters
                new { controller = "Category", action = "Index", key = "game" } // Parameter defaults
            );

            routes.MapRoute(
                null, // Route name
                "commodity/{cardKey}", // URL with parameters
                new { controller = "CardDetail", action = "Index", cardKey = UrlParameter.Optional } // Parameter defaults
            );

            routes.MapRoute(
                null, // Route name
                "game/{gameKey}", // URL with parameters
                new { controller = "Game", action = "Index", gameKey = UrlParameter.Optional } // Parameter defaults
            );

            routes.MapRoute(
                null, // Route name
                "purchasing-agency", // URL with parameters
                new { controller = "Delegation", action = "Index", gameKey = UrlParameter.Optional } // Parameter defaults
            );

            routes.MapRoute(
                null, // Route name
                "news", // URL with parameters
                new { controller = "News", action = "Index" } // Parameter defaults
            );

            routes.MapRoute(
                null, // Route name
                "news/{year}/{month}/{day}/{summary}", // URL with parameters
                new { controller = "News", action = "Detail" } // Parameter defaults
            );

            routes.MapRoute(
                null, // Route name
                "about", // URL with parameters
                new { controller = "Home", action = "About" } // Parameter defaults
            );

            routes.MapRoute(
                null, // Route name
                "user", // URL with parameters
                new { controller = "Customer", action = "Welcome" } // Parameter defaults
            );

            routes.MapRoute(
                null, // Route name
                "user/welcome", // URL with parameters
                new { controller = "Customer", action = "Welcome" } // Parameter defaults
            );

            routes.MapRoute(
                null, // Route name
                "user/profile", // URL with parameters
                new { controller = "Customer", action = "Profile" } // Parameter defaults
            );

            routes.MapRoute(
                null, // Route name
                "user/order", // URL with parameters
                new { controller = "Customer", action = "Order", ordertype = "tobepaid" } // Parameter defaults
            );

            routes.MapRoute(
                null, // Route name
                "user/order/{ordertype}", // URL with parameters
                new { controller = "Customer", action = "Order", ordertype = UrlParameter.Optional } // Parameter defaults
            );

            routes.MapRoute(
                null, // Route name
                "user/order/detail/{orderid}", // URL with parameters
                new { controller = "Customer", action = "OrderDetail" } // Parameter defaults
            );

            routes.MapRoute(
                null, // Route name
                "user/savings", // URL with parameters
                new { controller = "Customer", action = "Save" } // Parameter defaults
            );

            routes.MapRoute(
                null, // Route name
                "user/deposit", // URL with parameters
                new { controller = "Customer", action = "Deposit" } // Parameter defaults
            );

            routes.MapRoute(
                null, // Route name
                "user/recommend", // URL with parameters
                new { controller = "Customer", action = "Recommend" } // Parameter defaults
            );

            routes.MapRoute(
                null, // Route name
                "user/favorite/{page}", // URL with parameters
                new { controller = "Customer", action = "Favorite", page = UrlParameter.Optional } // Parameter defaults
            );


            routes.MapRoute(
                null, // Route name
                "user/red-envelope", // URL with parameters
                new { controller = "Customer", action = "Bonus" } // Parameter defaults
            );

            routes.MapRoute(
                null, // Route name
                "user/credits", // URL with parameters
                new { controller = "Customer", action = "Points" } // Parameter defaults
            );

            routes.MapRoute(
                null, // Route name
                "user/purchasing", // URL with parameters
                new { controller = "Customer", action = "Delegation" } // Parameter defaults
            );

            routes.MapRoute(
                null, // Route name
                "user/remittance", // URL with parameters
                new { controller = "Customer", action = "Remittance" } // Parameter defaults
            );

            routes.MapRoute(
                null, // Route name
                "user/alipay", // URL with parameters
                new { controller = "Customer", action = "Alipay" } // Parameter defaults
            );

            routes.MapRoute(
                null, // Route name
                "user/suggestion", // URL with parameters
                new { controller = "Complain", action = "Index" } // Parameter defaults
            );

            routes.MapRoute(
                null, // Route name
                "user/suggestion/create", // URL with parameters
                new { controller = "Complain", action = "Create" } // Parameter defaults
            );

            routes.MapRoute(
                null, // Route name
                "user/suggestion/{id}", // URL with parameters
                new { controller = "Complain", action = "Details" } // Parameter defaults
            );

            routes.MapRoute(
                null, // Route name
                "user/login", // URL with parameters
                new { controller = "Customer", action = "LogIn" } // Parameter defaults
            );

            routes.MapRoute(
                null, // Route name
                "user/logout", // URL with parameters
                new { controller = "Customer", action = "LogOut" } // Parameter defaults
            );

            routes.MapRoute(
                null, // Route name
                "user/register", // URL with parameters
                new { controller = "Customer", action = "Register" } // Parameter defaults
            );

            routes.MapRoute(
                null, // Route name
                "user/register-complete", // URL with parameters
                new { controller = "Customer", action = "RegisterComplete" } // Parameter defaults
            );

            routes.MapRoute(
                null, // Route name
                "user/email-not-verified", // URL with parameters
                new { controller = "Customer", action = "EmailNotVerified" } // Parameter defaults
            );

            routes.MapRoute(
                null, // Route name
                "user/register-succeed", // URL with parameters
                new { controller = "Customer", action = "RegisterSucceed" } // Parameter defaults
            );

            routes.MapRoute(
                null, // Route name
                "user/register-verify/{code}", // URL with parameters
                new { controller = "Customer", action = "RegisterVerify" } // Parameter defaults
            );

            routes.MapRoute(
                null, // Route name
                "user/forgotpwd", // URL with parameters
                new { controller = "Customer", action = "ForgotPwd" } // Parameter defaults
            );

            routes.MapRoute(
                null, // Route name
                "user/activate", // URL with parameters
                new { controller = "Customer", action = "Activate" } // Parameter defaults
            );

            routes.MapRoute(
                null, // Route name
                "user/verify", // URL with parameters
                new { controller = "Customer", action = "Verify" } // Parameter defaults
            );

            routes.MapRoute(
                null, // Route name
                "user/promote", // URL with parameters
                new { controller = "Customer", action = "Promote" } // Parameter defaults
            );

            routes.MapRoute(
                null, // Route name
                "user/change-password", // URL with parameters
                new { controller = "Customer", action = "ChangePassword" } // Parameter defaults
            );

            routes.MapRoute(
                null, // Route name
                "secure/install", // URL with parameters
                new { controller = "Deploy", action = "Install" } // Parameter defaults
            );

            routes.MapRoute(
                null, // Route name
                "express/{commodity}/{type}", // URL with parameters
                new { controller = "Purchase", action = "Express" } // Parameter defaults
            );

            routes.MapRoute(
                "confirm", // Route name
                "confirm", // URL with parameters
                new { controller = "Payment", action = "Confirm" } // Parameter defaults
            );

            routes.MapRoute(
                null, // Route name
                "checkout", // URL with parameters
                new { controller = "Payment", action = "Index" } // Parameter defaults
            );

            routes.MapRoute(
                null, // Route name
                "checkout/{payment}", // URL with parameters
                new { controller = "Payment", action = "Checkout" } // Parameter defaults
            );

            routes.MapRoute(
                null, // Route name
                "transaction-succeeded", // URL with parameters
                new { controller = "Payment", action = "TransSucceeded" } // Parameter defaults
            );

            routes.MapRoute(
                null, // Route name
                "transaction-failed", // URL with parameters
                new { controller = "Payment", action = "TransFailed" } // Parameter defaults
            );

            routes.MapRoute(
                null, // Route name
                "transaction-pending", // URL with parameters
                new { controller = "Payment", action = "TransPending" } // Parameter defaults
            );

            routes.MapRoute(
                null, // Route name
                "purchase/{commodity}/{type}/{currency}", // URL with parameters
                new { controller = "Purchase", action = "Index", currency = UrlParameter.Optional } // Parameter defaults
            );

            routes.MapRoute(
                null,
                "recommend/{cid}", // URL with parameters
                new { controller = "Home", action = "Recommend" } // Parameter defaults
            );

            routes.MapRoute(
                null,
                "throw", // URL with parameters
                new { controller = "Home", action = "_500" } // Parameter defaults
            );

            routes.MapRoute(
                null,
                "page-not-found", // URL with parameters
                new { controller = "Home", action = "_404" } // Parameter defaults
            );

            routes.MapRoute(
                "Default", // Route name
                "{controller}/{action}/{id}", // URL with parameters
                new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
            );

        }

        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);
        }
    }
}
